草庐IT

PHPUnit 和 CodeIgniter

全部标签

php - 使用 CodeIgniter 将上传图片字段添加到注册表单

我想在CodeIgniter中添加上传图片字段以注册表单.我在Controller中的注册码:functionadd_new_ticket(){if($this->input->post('fullname',TRUE)&&$this->input->post('nID',TRUE)&&$this->input->post('age',TRUE)&&$this->input->post('gender',TRUE)//&&$this->input->post('isFileID',TRUE)//&&$this->input->post('FileID',TRUE)&&$this->in

PHPUnit 测试写入文件的函数并将内容检查到创建的文件中

我正在为sonata/exporter做贡献,一个用于以多种格式(CSV、JSON、XML、XLS等)导出数据的库。我致力于通过封装另一个Writer(如CsvWriter或XlsWriter)将bool值转换为字符串(例如yes/no)的Writer。这是我第一次使用phpunit。对现有Writer进行的所有单元测试都使用此逻辑:-创建一个文件。-使用相应的格式将数据写入文件。-在file_get_contents(filename)上创建一个assertEquals。所以,我写了这个测试:publicfunctionsetUp(){$this->filename='formate

php - CodeIgniter:使用 HTTPS 和 AWS 时如何从 url 中删除 index.php

我使用HTTPS作为主要url,并且根据GoogleSEO指南,我必须设置以下重定向http://example.com/至https://example.comhttp://www.example.com/至https://example.comhttps://www.example.com/至https://example.com我配置的重定向非常适用于主页。但是对于内部页面,只有第一个有效,而第二个和第三个在url中添加index.php。示例https://www.example.com/index.php/mobiles/apple/apple-iphone-se至https

php - 如何在 codeigniter 中上传 2 个单独的图像

我想分别上传2张图片。我有一种情况,我需要上传文件,有时需要上传图像,有时只需要图像,我需要使用单独的按钮来区分图像和文件。我的代码是这是Controllerfunctionddoo_upload(){$config['upload_path']='./uploads/';$config['allowed_types']='gif|jpg|png';$config['max_size']='100';$config['max_width']='1024';$config['max_height']='768';$this->load->library('upload',$config)

PHPUnit 在应该为 200 时返回 404

我以前从未编写过测试用例,现在正尝试为我编写的API编写测试用例。我正在尝试使用post请求调用路由,因此我使用了以下内容:publicfunctiontestRequestCorrectApiKey(){//RequestwithX-AuthorizationsendingcorrectAPIKey$response=$this->call('POST','/authenticate',['email'=>'testingphpunit@phpunittest.com','password'=>'phpunittest',[],[],['X-Authorization'=>'123w

PHPUnit 静默失败

当我单独运行$phpunit时,它默默地失败了,这就是我试图知道问题所在但没有​​运气:$phpunit$echo$?=>255$php-i|grep错误display_errors=>STDOUT=>STDOUTdisplay_startup_errors=>On=>Onerror_append_string=>novalue=>novalueerror_log=>/usr/local/var/log/php_error.log=>/usr/local/var/log/php_error.logerror_prepend_string=>novalue=>novalueerror_r

php - 当我从 phpunit 登录时,当前用户的对象在 Symfony Controller 中为 NULL

我有PHPUnit的登录功能,并使用它作为测试用户进行授权。privatefunctionlogIn(Client$client){$session=$client->getContainer()->get('session');/**@varUser$user*/$user=$client->getContainer()->get('doctrine')->getRepository('DWDAdminBundle:User')->find(1);//HereIhaveuserobject$firewall='main';$token=newUsernamePasswordToken

PHPUnit 数据提供程序参数计数错误

我刚刚开始使用PHPUnit。到目前为止,除了DataProvider问题外,一切都很完美。问题是当我运行测试时,它通过了。但是,如果我再次运行它,它会失败并出现以下错误:ArgumentCountError:ToofewargumentstofunctionValidationTest::testValidateType(),0passedandatleast3expected如果我对数据提供程序函数进行任何更改(即更改要返回的数据、提供程序函数名称等)并重新运行,它会通过一次并失败,并在所有连续测试运行中出现上述错误。我使用的是最新版本的PHPUnit(一小时前更新)。不幸的是,我

php - 用于发送邮件的 SMTP 协议(protocol)不适用于 codeigniter

$config=Array('protocol'=>'smtp','smtp_host'=>'smtp.gmail.com','smtp_port'=>465,'smtp_user'=>'XXXX@XXXX.com','smtp_pass'=>'XXXX','mailtype'=>'html','charset'=>'iso-8859-1');$this->load->library('email',$config);$this->email->set_newline("\r\n");$this->email->from('xxxxx@xxx.com','xxxx');$this->e

php - 无法在 codeigniter 上运行 phpunit 测试,找不到 CI 错误

我在codeigniter上运行phpunittest,我有一个包含这段代码的admin_test.php文件。classAdmin_testextendsPHPUnit_Framework_TestCase{private$CI;publicfunction__construct(){//createinstancevariable$this->CI=&get_instance();}publicfunctiontestRenderReturnsHelloWorld(){$this->CI->load->controller('admin');$data=$this->admin->